﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;

namespace iSciences.Data
{
    [DataContract]
    public class Category
    {
        //==============================================
        // unique identifier 
        //==============================================
        Guid uniqueId;
        [DataMember]
        public Guid UniqueId
        {
            get { return uniqueId; }
            set { uniqueId = value; }
        }

        //==============================================
        // Category title 
        //==============================================
        string title;
        [DataMember]
        public string Title
        {
            get { return title != null ? title.Trim() : string.Empty; }
            set { title = value; }
        }

        //==============================================
        // Category des cription  
        //==============================================
        string description;
        [DataMember]
        public string Subtitle
        {
            get { return description != null ? description.Trim() : string.Empty; }
            set { description = value; }
        }

        //==============================================
        // Image url
        //==============================================
        private string imageUrl;
        [DataMember]
        public string ImageUrl
        {
            get { return imageUrl != null ? imageUrl : AppData._baseUri + "Assets/noimage.png"; }
            set { imageUrl = value; }
        }

        //==============================================
        // Categorie image  
        //==============================================
        private ImageSource image;
        public ImageSource Image
        {
            get
            {
                try
                {
                    BitmapImage img = new BitmapImage(new Uri(imageUrl));
                    img.DecodePixelHeight = 250;
                    img.DecodePixelWidth = 250;
                    return img;
                }
                catch (Exception)
                {
                    BitmapImage img = new BitmapImage(new Uri(AppData._baseUri, "Assets/noimage.png"));
                    img.DecodePixelHeight = 250;
                    img.DecodePixelWidth = 250;
                    return img;
                }
            }
            set
            {
               this.image = value;
            }
        }

        //==============================================
        // Category articles 
        //==============================================
        List<Article> articles;
        [DataMember]
        public List<Article> Articles
        {
            get
            {
                return articles;
            }
            set { articles = value; }
        }


        //==============================================
        // Constructors 
        //==============================================
        public Category(Guid uniqueId, string _name, string _description, string _imagePath, List<Article> articles)
        {
            this.uniqueId = uniqueId;
            this.title = _name;
            this.description = _description;
            this.imageUrl = _imagePath;
            this.articles = articles;
        }

        public Category()
        {
            this.uniqueId = Guid.NewGuid();
        }
    }
}
